# -*- mode: python ; coding: utf-8 -*-

from PyInstaller.utils.hooks import collect_data_files, collect_submodules
datas = collect_data_files('chromadb', include_py_files=True, includes=['**/*.py', '**/*.sql'])
datas += collect_data_files('unstructured', include_py_files=True, includes=['**/*.py', '**/*.txt'])
datas += collect_data_files('scipy', include_py_files=True, includes=['**/*.py', '**/*.pyx'])
datas += collect_data_files('sklearn', include_py_files=True, includes=['**/*.py', '**/*.pyx'])
app_name = 'yunhanAGI'
# datas.append(('data', 'data'))
a = Analysis(
    ['main-with-ollama.py'],
    pathex=['D:\\zfftools\\pcode\\ldllm\\'],
    binaries=[],
    datas=datas,
    hiddenimports=['onnxruntime', 'tokenizers', 'chromadb.telemetry.product.posthog', 'chromadb.telemetry.posthog', 'chromadb.api.segment','chromadb.db.impl',
'chromadb.db.impl.sqlite','chromadb.migrations', 'chromadb.migrations.embeddings_queue', 'hnswlib','passlib.handlers.bcrypt',
'openpyxl', 'pandas', 'unstructured', 'docx2txt', 'pypdf', 'xlrd', 'scipy.special._special_ufuncs', 'transformers.models.gemma2.configuration_gemma2'],
    collectsubmodules=['chromadb', 'chromadb.migrations', 'chromadb.telemetry', 'chromadb.api','chromadb.db'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='yunhanAGI',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon=['yunhan\\favicon.png'],
    uac_admin=True,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name=app_name,
)

import shutil
def copy_extra_resources(src_folder, dest_folder):
#    src_folder = 'path/to/your/folder'
    dest_folder = os.path.join(DISTPATH, dest_folder)
    if not os.path.exists(dest_folder):
        shutil.copytree(src_folder, dest_folder)

def copy_extra_file(src_file, dest_file):
#    src_folder = 'path/to/your/folder'
    dest_file = os.path.join(DISTPATH, dest_file)
    if not os.path.exists(dest_file):
        shutil.copy(src_file, dest_file)


block_cipher = None
# 添加下面两行来调用复制函数
copy_extra_resources('./data', './'+app_name+'/data')
copy_extra_resources('./yunhan', './'+app_name+'/yunhan')
copy_extra_resources('./static', './'+app_name+'/static')
copy_extra_resources('./soft', './'+app_name+'/soft')
copy_extra_file('./.env', './'+app_name+'/.env')